package com.epower.base;

import java.util.ArrayList;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport implements SessionAware {
	private static final long serialVersionUID = 7832295150101890553L;
	@SuppressWarnings("rawtypes")
	protected Map session;

	@SuppressWarnings("rawtypes")
	public void setSession(Map session) {
		this.session = session;
	}

	public ArrayList<Object> pages;

	/**
	 * 详细页码 如 1..34567..100
	 * 
	 * @return
	 * @throws Exception
	 */
	public ArrayList<Object> getPagesList(int nowPage, int totalPage) {
		if (nowPage > totalPage)
			nowPage = totalPage;

		int index = 1;
		ArrayList<Object> al = new ArrayList<Object>();
		al.add(index);
		index++;
		int from = 0;
		if (nowPage > 5 && nowPage <= totalPage - 1) {
			al.add("0");
			index++;
			from = nowPage - 2;
		} else
			from = 2;

		for (index = from; index < from + 5; index++) {
			if (index <= totalPage)
				al.add(index);
		}

		if (index < totalPage)
			al.add("0");

		if (index <= totalPage)
			al.add(totalPage);

		return al;
	}

	public ArrayList<Object> getPages() {
		return pages;
	}

	public void setPages(ArrayList<Object> pages) {
		this.pages = pages;
	}

}
